import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr


class Email(object):
    SENDER = '405117959@qq.com'
    PASS = 'brhqwwjmgwanbhid'

    @staticmethod
    def send(to, subject, message):
        try:
            msg = MIMEText(message, 'plain', 'utf-8')
            msg['From'] = formataddr(["Ole.Lee", Email.SENDER])
            msg['To'] = formataddr(["Ole.Lee", Email.SENDER])
            msg['Subject'] = subject

            server = smtplib.SMTP_SSL("smtp.qq.com", 465)
            server.login(Email.SENDER, Email.PASS)
            server.sendmail(Email.SENDER, [Email.SENDER, to], msg.as_string())
            server.quit()
            print('Email send success.')
        except Exception:
            print('Email send failed.')
